#!/bin/bash

set -e

if [[ -f /usr/share/glib-2.0/schemas/org.ukui.flash-disk.autoload.gschema.xml ]]; then
    gsettings set org.ukui.flash-disk.autoload ifautoload false
fi

#防止锁屏
gsettings set org.ukui.power-manager sleep-computer-ac -1 || true
gsettings set org.ukui.power-manager sleep-computer-battery -1 || true

gsettings set org.ukui.screensaver idle-lock -1 || true
gsettings set org.ukui.screensaver idle-delay -1 || true
gsettings set org.ukui.screensaver idle-activation-enabled false || true

gsettings set org.ukui.power-manager sleep-display-ac -1 || true
gsettings set org.ukui.power-manager sleep-display-battery -1 || true

GRANTED_XHOST_ROOT=no
if env | grep XDG_SESSION_TYPE|grep wayland > /dev/null 2>&1; then
	if ! xhost | grep -qi 'SI:localuser:root$'; then
		xhost +SI:localuser:root
		GRANTED_XHOST_ROOT=yes
	fi
fi

# 卸载可能由于自动挂载的目录
sudo umount /media/*/* || true

# 禁用 Win 键
sudo xmodmap -e "keycode 133 =" || true
sudo xmodmap -e "keycode 134 =" || true

sudo /usr/lib/udisks2/udisks2-inhibit /usr/bin/kylin-os-installer

if test "x$GRANTED_XHOST_ROOT" = 'xyes'; then
                xhost -SI:localuser:root
fi
